<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <template slot="footer">
      <template v-if="title === '详情'">
        <a-button @click="handleCancel">取消</a-button>
      </template>
      <template v-else-if="title === '版型审核'">
        <a-button @click="handleCancel">取消</a-button>
        <a-button type="primary" style="margin-left: 8px;" @click="handleReview('驳回')">驳回</a-button>
        <a-button type="primary" style="margin-left: 8px;" @click="handleReview('通过')">通过</a-button>
      </template>
      <template v-else>
        <a-button @click="handleCancel">取消</a-button>
        <a-button type="primary" style="margin-left: 8px;" @click="handleOk">确定</a-button>
      </template>
    </template>
    <product-library-version-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit"></product-library-version-form>
  </j-modal>
</template>

<script>

  import ProductLibraryVersionForm from './ProductLibraryVersionForm'
  export default {
    name: 'ProductLibraryVersionModal',
    components: {
      ProductLibraryVersionForm
    },
    data () {
      return {
        title:'',
        width:800,
        visible: false,
        disableSubmit: false
      }
    },
    methods: {
      add () {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.add();
        })
      },
      edit (record) {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.edit(record);
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        this.$refs.realForm.submitForm();
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      handleReview (type) {
        this.$refs.realForm.handleReview(type);
      },
    }
  }
</script>